package com.wzy.controller;


import com.wzy.pojo.Student;
import com.wzy.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping
    public String student(Model model){
        List<Student> students= studentService.findAllStudent();
        model.addAttribute("students",students);
        return "Student";
    }
    @RequestMapping("/updateS")
    public String updateS(Student student){
       studentService.updateStudent(student);
        return "redirect:/student";
    }
    @RequestMapping("/deleteS")
    public String deleteS(String ID){
        studentService.deleteStudent(ID);
        return "redirect:/student";
    }
    @RequestMapping("/addSPage")
    public String addSPage(){
        return "addStudent";
    }
    @RequestMapping("/addS")
    public String addStudent(Student student,Model model){
        if(studentService.addStudent(student)){
            return "redirect:/child#student";
        }else {
            model.addAttribute("addStudent", "没有找到孩子的父母");
            return "addStudent";
        }
    }
}
